/**
 * 
 */
package org.dragonfire.dasm;

import org.dragonfire.util.DString;

/**
 * @author Darth Android
 */
public class Command {

	private String name;
	private String[] params;

	public Command(String name, String[] params) {
		this.name = name;
		this.params = params;
	}

	public Command(String name, String params, char paramSep) {
		this(name, DString.splitTopLevel(params, paramSep));
	}

	public Command(String name, String params) {
		this(name, params, DASM.PARAM_SEP_CHAR);
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name.substring(isDirective() ? 1 : 0);
	}

	public boolean isDirective() {
		return name.charAt(0) == '#' || name.charAt(0) == '.';
	}

	/**
	 * @return the params
	 */
	public String[] getParams() {
		return params;
	}

	public String getRawParams() {
		return DString.join(getParams(), DASM.PARAM_SEP_CHAR + "");
	}

	public String getParam(int index) {
		if (params.length <= index)
			throw new CompileException("ERROR_NOT_ENOUGH_ARGS", index + 1);
		return params[index];
	}

	public String toString() {
		return name.toUpperCase() + " " + getRawParams();
	}
}
